home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Beginner: How to #include
- Date: Wed, 31 Jan 1996 02:14:29 GMT
- Organization: Netcom
- Message-ID: <310ecfc8.10036800@nntp.ix.netcom.com>
- References: <west.31.00844D6A@emt.e-technik.tu-muenchen.de>
- NNTP-Posting-Host: ix-dc9-11.ix.netcom.com
- X-NETCOM-Date: Tue Jan 30 6:15:00 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- west@emt.e-technik.tu-muenchen.de (Robert Westendorp) wrote:
-
- > Hi there,
- > I've got a principle question:
- >
- > I've got a project which consists of a couple of files.
- >
- > Let's say I define a struct including a member which is of a type
- > declared in direct.h
- >
- > First File: my_inc.h
- >
- > #include <direct.h>
- >
- > struct MYSTRUCT
- > {
- > _find_t fileinfo;
- > ....
- > }
- >
- > Then I want to use this struct in another file:
- >
- > struct MYSTRUCT my_variable;
- >
- > I will have to include my_inc.h, AND I will have to include direct.h;
- >
- > Now I have a couple of include files and it's very annoying always to include
- > those files down to direct.h, especially because I have to include them in the
- > right order.
- >
- > How can I solve this problem?
- > Include in include-files???
-
- That's how I do it. With rare exceptions, every file includes all the
- headers it needs to declare things it uses.
-
- There's one problem you need to handle. Sometimes including a file
- twice will cause errors. The way to handle this is to protect with
- #if. For example, the header myheader.h might look something like:
-
- #if !defined MYHEADER_H
- #define MYHEADER_H
- /* ... */
- #endif
-
-
- Michael M Rubenstein
-